//
//  AppDelegate.m
//  VwiovAPP
//
//  Created by WXC on 2018/3/22.
//  Copyright © 2018年 WXC. All rights reserved.
//

#import "AppDelegate.h"
#import <IQKeyboardManager/IQKeyboardManager.h>
#import "HomeController.h"

@interface AppDelegate ()
// 网络监控
@property (nonatomic, strong) Reachability *hostReach;
@property (nonatomic, assign) NetworkStatus curNetStatus;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    JYLog(@"%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]);
    // 启动图片延时: 1秒
    [NSThread sleepForTimeInterval:1];
    
    [IQKeyboardManager sharedManager].layoutIfNeededOnUpdate = YES;
//    layoutIfNeededOnUpdate
    // 设置白色的状态栏
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

    // 创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    
    self.window.rootViewController = [[JYNavigationController alloc] initWithRootViewController:[[HomeController alloc] init]];
    
    // 显示窗口
    [self.window makeKeyAndVisible];
    
    // 设置提示的最短时间
    [SVProgressHUD setMinimumDismissTimeInterval:1.5];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    // 监听网络
    [self initNetWorkObserver];

    return YES;
}



// 网络监控
- (void)initNetWorkObserver
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    
    //网络状态监测
    self.hostReach = [Reachability reachabilityForInternetConnection];
    self.curNetStatus = [self.hostReach currentReachabilityStatus];
    [self.hostReach startNotifier];
    [self updateInterfaceWithReachability];
}

// 网络连接改变
- (void)reachabilityChanged:(NSNotification *)note
{
    Reachability *curReach = [note object];
    if (curReach == _hostReach)
    {
        [self updateInterfaceWithReachability];
    }
}

// 处理连接改变后的情况
- (void)updateInterfaceWithReachability
{
    //对连接改变做出响应的处理动作。
    NetworkStatus status = [_hostReach currentReachabilityStatus];
    
    if (status != self.curNetStatus)
    {
        self.curNetStatus = status;
        
        if (self.curNetStatus == NotReachable)
        {
            JYLog(@"网络中断！！！！！！");
            [ShowInfoView showMessage:@"网络中断，请检查网络连接"];
        }
        else
        {
            JYLog(@"网络恢复！！！！！！");
             [ShowInfoView showMessage:@"网络已恢复"];
        }
    }
    else if (NotReachable == status)
    {
        JYLog(@"网络中断！！！！！！");
        
    }
}



@end
